<?php
namespace App\Services\Fund;
use App\Services\Fund\CurrencyAccount\CurrencyAccountLogic;
/**
 * 数字币冻结日志
 * Class CurrencyAccount
 * @package App\Services\Fund
 */
class CurrencyAccount
{
       //封装一层检验user_info、opposite_info后再执行stepRun <该页多数方法都需检验这两个json数据>
  /*  protected function _checkJsonThenRun(array $data, string $method, string $scene = ''): array 
    {
        if($data['user_info'] !== '{}'){ $data['user_info'] = json_encode($data['user_info']); }
        if($data['opposite_info'] !== '{}'){ $data['opposite_info'] = json_encode($data['opposite_info']); }
        if(isset($data['other_info']) && $data['other_info'] !== '{}'){ $data['other_info'] = json_encode($data['other_info']); }

        return $this->stepRun($data, $method, $scene);
    }*/
    
    /*兑换钱*/
    public function exchange(): array 
    {
        $data = $this->haveIssetReceiveData(['exchange'=>' ', 'money'=>0, 'app_id'=>0, 'currency_scale'=>' ']);

        $validate = validate($this->currencyAccountValidate);
        if(!$validate->scene('exchange')->check($data)){
            return verify_err(null, $validate->getError());
        }
        
        //无论是积分还是人民币去转换数字币 统一先转换为人民币后再进行亚数币转换
        $classPath = '\app\serverfund\logic' . '\\' . 'FundAccount';  
        $Obj = new $classPath($data);
        return $this->logic($this->currencyAccountLogic)->exchange($Obj, $data);
    }

    # 数字币 初始化数字币账户
  /*  public function init(): array
    {
        $data = $this->haveIssetReceiveData(['user_id'=>'0', 'create_ip'=>' ', 'app_id'=>' ']);
        return $this->stepRun($data, 'init', 'init');
    }*/

    # 数字币 充值 系统->a
   /* public function prepaid(): array
    {
        $data = $this->haveIssetReceiveData(['user_id'=>'0', 'currency'=>'0', 'update_ip'=>' ', 'app_id'=>' ', 'user_info'=>'{}','opposite_info'=>'{}', 'remark'=>'']);
        if(\SYSTEM_ID == $data['user_id']){
            return \verify_err($data, '不能为系统用户充值');
        }
        return $this->_checkJsonThenRun($data, 'prepaid', 'prepaid');
    }*/

    # 数字币转账 a->b 默认转账给系统（之前为系统扣除用户亚数币方法，改为转账）
  /*  public function deduct(): array 
    {
        $data = $this->haveIssetReceiveData(['user_id'=>'0', 'opposite_id'=>SYSTEM_ID, 'currency'=>'0', 'update_ip'=>' ', 'app_id'=>' ', 'user_info'=>'{}','opposite_info'=>'{}'], []);
        if(\SYSTEM_ID == $data['user_id']){
            return \verify_err($data, '不能扣除系统用户');
        }
        return $this->_checkJsonThenRun($data, 'deduct', 'deduct');
    }*/

    /*冻结数字币*/
  /*  public function freeze(): array
    {
        $data = $this->haveIssetReceiveData(['user_id'=>'0', 'opposite_id'=>'0', 'currency'=>'0', 'update_ip'=>' ', 'app_id'=>'0', 'user_info'=>'{}','opposite_info'=>'{}','type'=>' ','obj_id'=>' ','freeze_counts'=>1,'other_info'=>'{}']);
        return $this->_checkJsonThenRun($data, 'freeze', 'freeze');
    }*/

    /*后台管理员冻结某用户数字币*/
   /* public function adminFreeze(): array 
    {
        $data = $this->haveIssetReceiveData(['user_id'=>'0', 'opposite_id'=>'0', 'currency'=>'0', 'update_ip'=>' ', 'app_id'=>'0', 'user_info'=>'{}','opposite_info'=>'{}','reason'=>' ']);
        return $this->_checkJsonThenRun($data, 'adminFreeze', '');
    }*/

    /*解冻数字币*/
    /*public function unfreeze(): array
    {
        $data = $this->haveIssetReceiveData(['user_id'=>'0', 'opposite_id'=>'0', 'currency'=>'0', 'update_ip'=>' ', 'app_id'=>'0', 'type'=>' ','obj_id'=>' ','freeze_counts'=>' ', 'user_info'=>'{}','opposite_info'=>'{}','other_info'=>'{}','remark'=>'']);
        return $this->_checkJsonThenRun($data, 'unfreeze', 'unfreeze');
    }*/

    /*数字币账户列表*/
    public function list($data): array
    {
         $data = init_array($data,['page'=>'1', 'list_rows'=>'', 'keywords'=>'']);
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        ValidateCurrencyAccount::checkValidate($data, ['list_rows','page']);
        return (new CurrencyAccountLogic())->list($data);
    }

    /*指定用户的数字币账户列表*/
    public function listByUserIds($data): array
    {
         $data = init_array($data,['user_ids'=>' ','page'=>'1', 'list_rows'=>'']);
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        ValidateCurrencyAccount::checkValidate($data, ['user_ids']);
        return (new CurrencyAccountLogic())->listByUserIds($data);
    }

    /*余额付款的订单进行确认收货操作 opposite_id解list_rows冻user_id user_id转账opposite_id*/
    //解冻用户资金 用户转账平台资金
    //解冻用户积分 用户转账平台积分
    /*public function affirmPickUpGoods(): array 
    {
        $data = $this->haveIssetReceiveData(['user_id'=>0, 'opposite_id'=>0, 'currency'=>0, 'update_ip'=>' ', 'app_id'=>0, 'user_info'=>'{}', 'opposite_info'=>'{}', 'type'=>' ', 'obj_id'=>' ', 'freeze_counts'=>' ', 'integral'=>0]);
        if(!$data['currency'] && !$data['integral']){
            return verify_err(null, '亚数币与积分不能同时为0');
        }
        return $this->_checkJsonThenRun($data, 'affirmPickUpGoods', 'affirmPickUpGoods');
    }*/

    /*根据查询条件获取已冻结的最大次数*/
    /*public function getFreezeCounts(): array 
    {
        $data = $this->haveIssetReceiveData(['user_id'=>' ', 'app_id'=>' ', 'type'=>' ', 'obj_id'=>' ', 'freeze_status'=>' '], []);
        return $this->stepRun($data, 'getFreezeCounts');
    }*/

}